package com.lcu.bos.service.impl;

import com.lcu.bos.modle.Decidedzone;
import com.lcu.bos.modle.Noticebill;
import com.lcu.bos.modle.Staff;
import com.lcu.bos.modle.Workbill;
import com.lcu.bos.service.INoticebillService;
import com.lcu.bos.service.base.BaseServiceImpl;
import com.lcu.bos.untils.BOSContextUntils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
@Service
@Transactional
public class NoticebillServiceImp extends BaseServiceImpl<Noticebill> implements INoticebillService {

    @Override
    public void save(Noticebill entity) {
        //1.添加新增类型
        entity.setOrdertype("新增");
        //设置客服id
        entity.setUser(BOSContextUntils.loginUser());
        Staff staff=null;
        noticebillDao.save(entity);
    }
    public void save(Noticebill entity,String decidezoneId) {
        //1.添加新增类型
        entity.setOrdertype("手动");
        //设置客服id
        entity.setUser(BOSContextUntils.loginUser());

        noticebillDao.save(entity);//先保存后，工单才有主键
        //3.自动分单【通过定区找到负责人  （实现后台智能分单的功能）】
        if(!StringUtils.isEmpty(decidezoneId)){
            entity.setOrdertype("自动");
            Decidedzone dc = decidedzoneDao.find(decidezoneId);
            Staff staff=dc.getStaff();
            entity.setStaff(staff);
            //往工单表里插入数据
            Workbill workbill=new Workbill();
            workbill.setType("新单");//工单类型 ：新、追、改、销
            workbill.setPickstate("未取件");//未、中、收
            workbill.setBuildtime(new Timestamp(System.currentTimeMillis()));//工单创建时间
            workbill.setAttachbilltimes(0);//取到快件时间
            workbill.setRemark(entity.getRemark());
            //往工单中添加
            workbill.setNoticebill(entity);
            workcillDao.save(workbill);
        }

    }
    @Override
    public void delete(Noticebill entity) {

    }

    @Override
    public void update(Noticebill entity) {

    }

    @Override
    public Noticebill find(Serializable id) {
        return null;
    }

    @Override
    public List<Noticebill> findAll() {
        return null;
    }
}
